<?php
	//处理请求
	$_GET += url_parse('route');

	isset($_GET['path']) AND $_GET['path'] =  decode($_GET['path']);
	$_REQUEST = array_merge($_GET,$_POST,$_COOKIE);
	// 获取上次请求 url
	$REFERER = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:create_url('index','',get_now_path());
	//处理 操作 url 参数
	function url_parse($route = 'route',$Delimiter = '-'){
		return isset($_GET['route'])?explode($Delimiter, $_GET['route']):[];
	}
	
	function param($key, $defval = '') {
		if(!isset($_REQUEST[$key]) || ($key === 0 && empty($_REQUEST[$key]))) {
			// if(is_array($defval)) {
			// 	return array();
			// } else {
			// 	return $defval;
			// }
			return $defval;
		}
		return $_REQUEST[$key];
	}

	function create_url($handle,$action = '',$args = []){
		$url = '?route='.$handle;
		empty($action) or $url .= '-'.$action;
		$str = '';
		if (!empty($args) && is_array($args)) {
			foreach ($args as $key => $value) {
				if ($key === 'path') {
					$value = strpos($value,handle_dir($GLOBALS['conf']['root_path'])) === FALSE?handle_dir($GLOBALS['conf']['root_path']):$value;
				}
				$str.= '&'.$key.'='.encode($value);
			}
		}elseif(is_string($args)){
			$str.= '&path='.encode($args);
		} 
		return $url.$str;
	}
	//跳转
	function jump($message, $url = '',$type = false, $delay = 3){
		header('HTTP/1.1 301 Moved Permanently');
		$url == 'back' AND $url = 'javascript:history.back()';
		assign('url',$url);
		assign('type',$type);
		assign('delay',$delay);
		assign('message',$message);
		view('jump');
	}



	